﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data.Common;
using System.Data;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using TRPOP.CRM.Component.Model;
using TRPOP.Common;

namespace TRPOP.CRM.Component.DALSQLServer
{
    public class CompanyDAL
    {

        private static TRPOP.ComSqlDAL.ICommonDAL CommonDAL = new TRPOP.ComSqlDAL.CommonDAL();
        #region 私有的方法
        ///	<summary>
        ///	从Table取数据到实体
        ///	</summary>
        ///	<param name="oDataRow">数据行</param>
        ///	<returns>返回实体</returns>
        private static CompanyInfo ParseRowTomodel(DataRow oDataRow)
        {
            CompanyInfo oInfo = new CompanyInfo();
            oInfo.nvcCompanyName = oDataRow["nvcCompanyName"] is DBNull ? "" : (string)oDataRow["nvcCompanyName"];
            oInfo.nvcContactName = oDataRow["nvcContactName"] is DBNull ? "" : (string)oDataRow["nvcContactName"];
            oInfo.bGender = oDataRow["bGender"] is DBNull ? false : (bool)oDataRow["bGender"];
            oInfo.nvcRegisterAdress = oDataRow["nvcRegisterAdress"] is DBNull ? "" : (string)oDataRow["nvcRegisterAdress"];
            oInfo.nvcContactAddress = oDataRow["nvcContactAddress"] is DBNull ? "" : (string)oDataRow["nvcContactAddress"];
            oInfo.nvcContactPhone = oDataRow["nvcContactPhone"] is DBNull ? "" : (string)oDataRow["nvcContactPhone"];
            oInfo.nvcContactTel = oDataRow["nvcContactTel"] is DBNull ? "" : (string)oDataRow["nvcContactTel"];
            oInfo.nvcFax = oDataRow["nvcFax"] is DBNull ? "" : (string)oDataRow["nvcFax"];
            oInfo.nvcEmail = oDataRow["nvcEmail"] is DBNull ? "" : (string)oDataRow["nvcEmail"];
            oInfo.nvcPostCode = oDataRow["nvcPostCode"] is DBNull ? "" : (string)oDataRow["nvcPostCode"];
            oInfo.nvcQQ = oDataRow["nvcQQ"] is DBNull ? "" : (string)oDataRow["nvcQQ"];
            oInfo.nvcWebSite = oDataRow["nvcWebSite"] is DBNull ? "" : (string)oDataRow["nvcWebSite"];
            oInfo.nvcArea = oDataRow["nvcArea"] is DBNull ? "" : (string)oDataRow["nvcArea"];
            oInfo.nvcDiscription = oDataRow["nvcDiscription"] is DBNull ? "" : (string)oDataRow["nvcDiscription"];
            oInfo.nvcCountry = oDataRow["nvcCountry"] is DBNull ? "" : (string)oDataRow["nvcCountry"];
            oInfo.nvcProvince = oDataRow["nvcProvince"] is DBNull ? "" : (string)oDataRow["nvcProvince"];
            oInfo.nvcCity = oDataRow["nvcCity"] is DBNull ? "" : (string)oDataRow["nvcCity"];
            oInfo.dtCreationTime = oDataRow["dtCreationTime"] is DBNull ? (new DateTime(1900, 1, 1)) : (DateTime)oDataRow["dtCreationTime"];
            oInfo.iCreatByEmployee = oDataRow["iCreatByEmployee"] is DBNull ? 0 : (int)oDataRow["iCreatByEmployee"];
            oInfo.iCompanyStatus = oDataRow["iCompanyStatus"] is DBNull ? 0 : (int)oDataRow["iCompanyStatus"];
            oInfo.ntExtendProperty = oDataRow["ntExtendProperty"] is DBNull ? "" : (string)oDataRow["ntExtendProperty"];
            oInfo.iCompanyCategoryID = oDataRow["iCompanyCategoryID"] is DBNull ? 0 : (int)oDataRow["iCompanyCategoryID"];
            oInfo.iCompanyGradeID = oDataRow["iCompanyGradeID"] is DBNull ? 0 : (int)oDataRow["iCompanyGradeID"];
            oInfo.iCompanySourceID = oDataRow["iCompanySourceID"] is DBNull ? 0 : (int)oDataRow["iCompanySourceID"];
            oInfo.iEmployeeFollowup = oDataRow["iEmployeeFollowup"] is DBNull ? 0 : (int)oDataRow["iEmployeeFollowup"];
            oInfo.iCompanyID = oDataRow["iCompanyID"] is DBNull ? 0 : (int)oDataRow["iCompanyID"];
            return oInfo;
        }


        ///	<summary>
        ///	通用的添加存储过程的变量
        ///	</summary>
        ///	<param name="osdDataBase">SqlDatabase</param>
        ///	<param name="odbCommand">DbCommand</param>
        ///	<param name="oInfo">实体</param>
        private static CompanyInfo ParseModeltoParam(SqlDatabase odbDataBase, DbCommand odbCommand, CompanyInfo oInfo)
        {
            odbDataBase.AddInParameter(odbCommand, "@nvcCompanyName", System.Data.DbType.String, oInfo.nvcCompanyName);
            odbDataBase.AddInParameter(odbCommand, "@nvcContactName", System.Data.DbType.String, oInfo.nvcContactName);
            odbDataBase.AddInParameter(odbCommand, "@bGender", System.Data.DbType.Boolean, oInfo.bGender);
            odbDataBase.AddInParameter(odbCommand, "@nvcRegisterAdress", System.Data.DbType.String, oInfo.nvcRegisterAdress);
            odbDataBase.AddInParameter(odbCommand, "@nvcContactAddress", System.Data.DbType.String, oInfo.nvcContactAddress);
            odbDataBase.AddInParameter(odbCommand, "@nvcContactPhone", System.Data.DbType.String, oInfo.nvcContactPhone);
            odbDataBase.AddInParameter(odbCommand, "@nvcContactTel", System.Data.DbType.String, oInfo.nvcContactTel);
            odbDataBase.AddInParameter(odbCommand, "@nvcFax", System.Data.DbType.String, oInfo.nvcFax);
            odbDataBase.AddInParameter(odbCommand, "@nvcEmail", System.Data.DbType.String, oInfo.nvcEmail);
            odbDataBase.AddInParameter(odbCommand, "@nvcPostCode", System.Data.DbType.String, oInfo.nvcPostCode);
            odbDataBase.AddInParameter(odbCommand, "@nvcQQ", System.Data.DbType.String, oInfo.nvcQQ);
            odbDataBase.AddInParameter(odbCommand, "@nvcWebSite", System.Data.DbType.String, oInfo.nvcWebSite);
            odbDataBase.AddInParameter(odbCommand, "@nvcArea", System.Data.DbType.String, oInfo.nvcArea);
            odbDataBase.AddInParameter(odbCommand, "@nvcDiscription", System.Data.DbType.String, oInfo.nvcDiscription);
            odbDataBase.AddInParameter(odbCommand, "@nvcCountry", System.Data.DbType.String, oInfo.nvcCountry);
            odbDataBase.AddInParameter(odbCommand, "@nvcProvince", System.Data.DbType.String, oInfo.nvcProvince);
            odbDataBase.AddInParameter(odbCommand, "@nvcCity", System.Data.DbType.String, oInfo.nvcCity);
            odbDataBase.AddInParameter(odbCommand, "@dtCreationTime", System.Data.DbType.DateTime, oInfo.dtCreationTime);
            odbDataBase.AddInParameter(odbCommand, "@iCreatByEmployee", System.Data.DbType.Int32, oInfo.iCreatByEmployee);
            odbDataBase.AddInParameter(odbCommand, "@iCompanyStatus", System.Data.DbType.Int32, oInfo.iCompanyStatus);
            odbDataBase.AddInParameter(odbCommand, "@ntExtendProperty", System.Data.DbType.String, oInfo.ntExtendProperty);
            odbDataBase.AddInParameter(odbCommand, "@iCompanyCategoryID", System.Data.DbType.Int32, oInfo.iCompanyCategoryID);
            odbDataBase.AddInParameter(odbCommand, "@iCompanyGradeID", System.Data.DbType.Int32, oInfo.iCompanyGradeID);
            odbDataBase.AddInParameter(odbCommand, "@iCompanySourceID", System.Data.DbType.Int32, oInfo.iCompanySourceID);
            odbDataBase.AddInParameter(odbCommand, "@iEmployeeFollowup", System.Data.DbType.Int32, oInfo.iEmployeeFollowup);
            odbDataBase.AddParameter(odbCommand, "@iCompanyID", System.Data.DbType.Int32, ParameterDirection.InputOutput, null, DataRowVersion.Default, oInfo.iCompanyID);
            return oInfo;
        }


        #endregion

        ///	<summary>
        ///	 更新或添加
        ///	</summary>
        ///	<param name="oInfo"></param>
        ///	<returns>bool</returns>
        public bool Save(CompanyInfo oInfo)
        {
            bool flag = false;
            try
            {
                SqlDatabase odbDataBase = new SqlDatabase(SystemInfoHelper.getSystemInfo().DataBaseConnection);
                DbCommand odbCommand = odbDataBase.GetStoredProcCommand("Company_Save");
                ParseModeltoParam(odbDataBase, odbCommand, oInfo);
                odbDataBase.ExecuteNonQuery(odbCommand);
                oInfo.iCompanyID = (int)odbDataBase.GetParameterValue(odbCommand, "@iCompanyID");
                flag = true;
            }
            catch (Exception oeException)
            {
                throw new Exception(oeException.Message, oeException);
            }
            return flag;
        }

        ///	<summary>
        ///	根据Primary Key获取信息实体
        ///	</summary>
        ///	<param name="intiCompanyID"></param>
        ///	<returns>CompanyInfo</returns>
        public CompanyInfo GetInfoById(int intiCompanyID)
        {
            CompanyInfo oInfo = null;
            string strSqlString = "SELECT * FROM Company WHERE  iCompanyID=" + intiCompanyID + "    ";
            try
            {
                DataSet oDataSet = CommonDAL.GetDataSet(strSqlString, SystemInfoHelper.getSystemInfo().DataBaseConnection);
                DataTable oDataTable = oDataSet.Tables[0];
                if (oDataTable.Rows.Count == 1)
                {
                    oInfo = ParseRowTomodel(oDataTable.Rows[0]);
                }
            }
            catch (Exception oeException)
            {
                throw new Exception(oeException.Message, oeException);
            }
            return oInfo;
        }

        ///	<summary>
        ///	 根据Primary Key删除信息实体
        ///	</summary>
        ///	<param name="intiCompanyID"></param>
        ///	<returns>bool</returns>
        public bool DeleteInfoById(int intiCompanyID)
        {
            return DeleteInfoByIds(intiCompanyID.ToString());
        }

        /// <summary>
        /// 批量删除客户信息
        /// </summary>
        /// <param name="strIDs"></param>
        /// <returns></returns>
        public bool DeleteInfoByIds(string strIDs)
        {
            string strSqlString = string.Format(@"
                    DELETE FROM  WorkComment WHERE iWorkingLogID IN ( SELECT iWorkingLogID FROM WorkingLog WHERE  iCompanyID IN ({0} ) );
                    DELETE FROM  WorkingLog WHERE iCompanyID IN ({0} );
                    DELETE FROM  CompanyRemind WHERE iCompanyID IN ({0} )
                    ", strIDs);
            try
            {
                CommonDAL.ExeSQLQuery(strSqlString, SystemInfoHelper.getSystemInfo().DataBaseConnection);
                strSqlString = "DELETE FROM Company WHERE   iCompanyID in (" + strIDs + " )   ";
                if (CommonDAL.ExeSQLQuery(strSqlString, SystemInfoHelper.getSystemInfo().DataBaseConnection) == EnumSubmitResult.Success)
                {
                    return true;
                }
                return false;
            }
            catch (Exception oeException)
            {
                throw new Exception(oeException.Message, oeException);
            }
        }

        ///	<summary>
        ///	 获取信息列表（无分页）
        ///	</summary>
        ///	<param name="intTopn">前N条，为0时表示所有符合条件的</param>
        ///	<param name="strCondition">自定义条件，要以And开头</param>
        ///	<param name="strOrderby">排序，不需要Order by </param>
        ///	<returns>List<CompanyInfo></returns>
        public List<CompanyInfo> GetListByCondition(int intTopn, string strCondition, string strOrderby)
        {
            List<CompanyInfo> oList = new List<CompanyInfo>();
            string strSql = CommonDAL.strbuildSqlForList(intTopn, strCondition, strOrderby, "Company");
            try
            {
                DataSet oDataSet = CommonDAL.GetDataSet(strSql, SystemInfoHelper.getSystemInfo().DataBaseConnection);
                DataTable oDataTable = oDataSet.Tables[0];
                foreach (DataRow otempRow in oDataTable.Rows)
                {
                    oList.Add(ParseRowTomodel(otempRow));
                }
            }
            catch (Exception oeException)
            {
                throw new Exception(oeException.Message, oeException);
            }
            return oList;
        }

        ///	<summary>
        ///	获取分页信息
        ///	</summary>
        /// <param name="intPageNumber">当前页页码</param>
        /// <param name="intPageSize">分页大小</param>
        /// <param name="strCondition">查询条件 and ....</param>
        /// <param name="strOrderby">排序的字段名 id desc</param>
        /// <param name="intRecordCount">总记录数</param>
        ///	<returns>List<CompanyInfo></returns>
        public List<CompanyInfo> GetListByPager(int intPageNumber, int intPageSize, string strCondition, string strOrderby, out int intRecordCount)
        {
            List<CompanyInfo> oList = new List<CompanyInfo>();
            try
            {
                DataSet oDataSet = CommonDAL.GetListByPager("Company", "*", intPageNumber, intPageSize, strCondition, strOrderby, out  intRecordCount, SystemInfoHelper.getSystemInfo().DataBaseConnection);
                DataTable oDataTable = oDataSet.Tables[0];
                foreach (DataRow otempRow in oDataTable.Rows)
                {
                    oList.Add(ParseRowTomodel(otempRow));
                }
            }
            catch (Exception oeException)
            {
                throw new Exception(oeException.Message, oeException);
            }
            return oList;
        }

        #region CompanyExtraInfo
        ///	<summary>
        ///	从Table取数据到实体
        ///	</summary>
        ///	<param name="oDataRow">数据行</param>
        ///	<returns>返回实体</returns>
        private static CompanyExtraInfo ParseRowExtraTomodel(DataRow oDataRow)
        {
            CompanyExtraInfo oInfo = new CompanyExtraInfo();
            oInfo.nvcCompanyName = oDataRow["nvcCompanyName"] is DBNull ? "" : (string)oDataRow["nvcCompanyName"];
            oInfo.nvcContactName = oDataRow["nvcContactName"] is DBNull ? "" : (string)oDataRow["nvcContactName"];
            oInfo.bGender = oDataRow["bGender"] is DBNull ? false : (bool)oDataRow["bGender"];
            oInfo.nvcRegisterAdress = oDataRow["nvcRegisterAdress"] is DBNull ? "" : (string)oDataRow["nvcRegisterAdress"];
            oInfo.nvcContactAddress = oDataRow["nvcContactAddress"] is DBNull ? "" : (string)oDataRow["nvcContactAddress"];
            oInfo.nvcContactPhone = oDataRow["nvcContactPhone"] is DBNull ? "" : (string)oDataRow["nvcContactPhone"];
            oInfo.nvcContactTel = oDataRow["nvcContactTel"] is DBNull ? "" : (string)oDataRow["nvcContactTel"];
            oInfo.nvcFax = oDataRow["nvcFax"] is DBNull ? "" : (string)oDataRow["nvcFax"];
            oInfo.nvcEmail = oDataRow["nvcEmail"] is DBNull ? "" : (string)oDataRow["nvcEmail"];
            oInfo.nvcPostCode = oDataRow["nvcPostCode"] is DBNull ? "" : (string)oDataRow["nvcPostCode"];
            oInfo.nvcQQ = oDataRow["nvcQQ"] is DBNull ? "" : (string)oDataRow["nvcQQ"];
            oInfo.nvcWebSite = oDataRow["nvcWebSite"] is DBNull ? "" : (string)oDataRow["nvcWebSite"];
            oInfo.nvcArea = oDataRow["nvcArea"] is DBNull ? "" : (string)oDataRow["nvcArea"];
            oInfo.nvcDiscription = oDataRow["nvcDiscription"] is DBNull ? "" : (string)oDataRow["nvcDiscription"];
            oInfo.nvcCountry = oDataRow["nvcCountry"] is DBNull ? "" : (string)oDataRow["nvcCountry"];
            oInfo.nvcProvince = oDataRow["nvcProvince"] is DBNull ? "" : (string)oDataRow["nvcProvince"];
            oInfo.nvcCity = oDataRow["nvcCity"] is DBNull ? "" : (string)oDataRow["nvcCity"];
            oInfo.dtCreationTime = oDataRow["dtCreationTime"] is DBNull ? (new DateTime(1900, 1, 1)) : (DateTime)oDataRow["dtCreationTime"];
            oInfo.iCreatByEmployee = oDataRow["iCreatByEmployee"] is DBNull ? 0 : (int)oDataRow["iCreatByEmployee"];
            oInfo.iCompanyStatus = oDataRow["iCompanyStatus"] is DBNull ? 0 : (int)oDataRow["iCompanyStatus"];
            oInfo.ntExtendProperty = oDataRow["ntExtendProperty"] is DBNull ? "" : (string)oDataRow["ntExtendProperty"];
            oInfo.iCompanyCategoryID = oDataRow["iCompanyCategoryID"] is DBNull ? 0 : (int)oDataRow["iCompanyCategoryID"];
            oInfo.iCompanyGradeID = oDataRow["iCompanyGradeID"] is DBNull ? 0 : (int)oDataRow["iCompanyGradeID"];
            oInfo.iCompanySourceID = oDataRow["iCompanySourceID"] is DBNull ? 0 : (int)oDataRow["iCompanySourceID"];
            oInfo.iEmployeeFollowup = oDataRow["iEmployeeFollowup"] is DBNull ? 0 : (int)oDataRow["iEmployeeFollowup"];
            oInfo.iCompanyID = oDataRow["iCompanyID"] is DBNull ? 0 : (int)oDataRow["iCompanyID"];

            oInfo.nvcCompanyCategoryName = oDataRow["nvcCompanyCategoryName"] is DBNull ? "" : (string)oDataRow["nvcCompanyCategoryName"];
            oInfo.nvcCompanyGradeName = oDataRow["nvcCompanyGradeName"] is DBNull ? "" : (string)oDataRow["nvcCompanyGradeName"];
            oInfo.nvcCompanySourceName = oDataRow["nvcCompanySourceName"] is DBNull ? "" : (string)oDataRow["nvcCompanySourceName"];
            
            if (oDataRow.Table.Columns.Contains("nvcEmployeeName"))
            {
                oInfo.nvcEmployeeName = oDataRow["nvcEmployeeName"] is DBNull ? "" : (string)oDataRow["nvcEmployeeName"];
            }
            return oInfo;
        }

        /// <summary>
        /// 分页获取所有的 CompanyExtraInfo
        /// </summary>
        /// <param name="intPageNumber"></param>
        /// <param name="intPageSize"></param>
        /// <param name="strCondition"></param>
        /// <param name="strOrderby"></param>
        /// <param name="intRecordCount"></param>
        /// <returns></returns>
        public List<CompanyExtraInfo> GetExtraInfoListByPager(int intPageNumber, int intPageSize, string strCondition, string strOrderby, out int intRecordCount)
        {
            List<CompanyExtraInfo> oList = new List<CompanyExtraInfo>();
            try
            {
                DataSet oDataSet = CommonDAL.GetListByPager("vw_Company", "*", intPageNumber, intPageSize, strCondition, strOrderby, out  intRecordCount, SystemInfoHelper.getSystemInfo().DataBaseConnection);
                DataTable oDataTable = oDataSet.Tables[0];
                foreach (DataRow otempRow in oDataTable.Rows)
                {
                    oList.Add(ParseRowExtraTomodel(otempRow));
                }
            }
            catch (Exception oeException)
            {
                throw new Exception(oeException.Message, oeException);
            }
            return oList;
        }
        /// <summary>
        /// 检测CompanyNumber是否已存在
        /// </summary>
        /// <param name="strCompanyNumber">CompanyNumber</param>
        /// <returns>True：已存在；False：不存在</returns>
        public bool CheckCompanyNumberExist(string strCompanyNumber)
        {
            bool bReturn = false;

            string strSqlString = "SELECT * FROM Employee WHERE nvcEmployeeNumber='" + strCompanyNumber + "'";
            try
            {
                DataSet oDataSet = CommonDAL.GetDataSet(strSqlString, SystemInfoHelper.getSystemInfo().DataBaseConnection);
                DataTable oDataTable = oDataSet.Tables[0];
                if (oDataTable.Rows.Count > 0)
                {
                    bReturn = true;
                }
            }
            catch (Exception oeException)
            {
                throw new Exception(oeException.Message, oeException);
            }

            return bReturn;
        }

        /// <summary>
        /// 检测CompanyName是否已存在
        /// </summary>
        /// <param name="strCompanyName">CompanyName</param>
        /// <returns>True：已存在；False：不存在</returns>
        public bool CheckCompanyNameExist(string strCompanyName)
        {
            bool bReturn = false;

            string strSqlString = "SELECT * FROM Company WHERE nvcCompanyName='" + strCompanyName + "'";
            try
            {
                DataSet oDataSet = CommonDAL.GetDataSet(strSqlString, SystemInfoHelper.getSystemInfo().DataBaseConnection);
                DataTable oDataTable = oDataSet.Tables[0];
                if (oDataTable.Rows.Count > 0)
                {
                    bReturn = true;
                }
            }
            catch (Exception oeException)
            {
                throw new Exception(oeException.Message, oeException);
            }

            return bReturn;
        }
        #endregion

        #region CompanyRemindInfo
        ///	<summary>
        ///	从Table取数据到实体
        ///	</summary>
        ///	<param name="oDataRow">数据行</param>
        ///	<returns>返回实体</returns>
        private static CompanyRemindExtraInfo ParseRowRemindTomodel(DataRow oDataRow)
        {
            CompanyRemindExtraInfo oInfo = new CompanyRemindExtraInfo();
            oInfo.nvcCompanyName = oDataRow["nvcCompanyName"] is DBNull ? "" : (string)oDataRow["nvcCompanyName"];
            oInfo.nvcContactName = oDataRow["nvcContactName"] is DBNull ? "" : (string)oDataRow["nvcContactName"];
            oInfo.bGender = oDataRow["bGender"] is DBNull ? false : (bool)oDataRow["bGender"];
            oInfo.nvcRegisterAdress = oDataRow["nvcRegisterAdress"] is DBNull ? "" : (string)oDataRow["nvcRegisterAdress"];
            oInfo.nvcContactAddress = oDataRow["nvcContactAddress"] is DBNull ? "" : (string)oDataRow["nvcContactAddress"];
            oInfo.nvcContactPhone = oDataRow["nvcContactPhone"] is DBNull ? "" : (string)oDataRow["nvcContactPhone"];
            oInfo.nvcContactTel = oDataRow["nvcContactTel"] is DBNull ? "" : (string)oDataRow["nvcContactTel"];
            oInfo.nvcFax = oDataRow["nvcFax"] is DBNull ? "" : (string)oDataRow["nvcFax"];
            oInfo.nvcEmail = oDataRow["nvcEmail"] is DBNull ? "" : (string)oDataRow["nvcEmail"];
            oInfo.nvcPostCode = oDataRow["nvcPostCode"] is DBNull ? "" : (string)oDataRow["nvcPostCode"];
            oInfo.nvcQQ = oDataRow["nvcQQ"] is DBNull ? "" : (string)oDataRow["nvcQQ"];
            oInfo.nvcWebSite = oDataRow["nvcWebSite"] is DBNull ? "" : (string)oDataRow["nvcWebSite"];
            oInfo.nvcArea = oDataRow["nvcArea"] is DBNull ? "" : (string)oDataRow["nvcArea"];
            oInfo.nvcDiscription = oDataRow["nvcDiscription"] is DBNull ? "" : (string)oDataRow["nvcDiscription"];
            oInfo.nvcCountry = oDataRow["nvcCountry"] is DBNull ? "" : (string)oDataRow["nvcCountry"];
            oInfo.nvcProvince = oDataRow["nvcProvince"] is DBNull ? "" : (string)oDataRow["nvcProvince"];
            oInfo.nvcCity = oDataRow["nvcCity"] is DBNull ? "" : (string)oDataRow["nvcCity"];
            oInfo.dtCreationTime = oDataRow["dtCreationTime"] is DBNull ? (new DateTime(1900, 1, 1)) : (DateTime)oDataRow["dtCreationTime"];
            oInfo.iCreatByEmployee = oDataRow["iCreatByEmployee"] is DBNull ? 0 : (int)oDataRow["iCreatByEmployee"];
            oInfo.iCompanyStatus = oDataRow["iCompanyStatus"] is DBNull ? 0 : (int)oDataRow["iCompanyStatus"];
            oInfo.ntExtendProperty = oDataRow["ntExtendProperty"] is DBNull ? "" : (string)oDataRow["ntExtendProperty"];
            oInfo.iCompanyCategoryID = oDataRow["iCompanyCategoryID"] is DBNull ? 0 : (int)oDataRow["iCompanyCategoryID"];
            oInfo.iCompanyGradeID = oDataRow["iCompanyGradeID"] is DBNull ? 0 : (int)oDataRow["iCompanyGradeID"];
            oInfo.iCompanySourceID = oDataRow["iCompanySourceID"] is DBNull ? 0 : (int)oDataRow["iCompanySourceID"];
            oInfo.iEmployeeFollowup = oDataRow["iEmployeeFollowup"] is DBNull ? 0 : (int)oDataRow["iEmployeeFollowup"];
            oInfo.iCompanyID = oDataRow["iCompanyID"] is DBNull ? 0 : (int)oDataRow["iCompanyID"];

            oInfo.nvcCompanyCategoryName = oDataRow["nvcCompanyCategoryName"] is DBNull ? "" : (string)oDataRow["nvcCompanyCategoryName"];
            oInfo.nvcCompanyGradeName = oDataRow["nvcCompanyGradeName"] is DBNull ? "" : (string)oDataRow["nvcCompanyGradeName"];
            oInfo.nvcCompanySourceName = oDataRow["nvcCompanySourceName"] is DBNull ? "" : (string)oDataRow["nvcCompanySourceName"];

            oInfo.dtStartTime = oDataRow["dtStartTime"] is DBNull ? (new DateTime(1900, 1, 1)) : (DateTime)oDataRow["dtStartTime"];
            oInfo.dtEndTime = oDataRow["dtEndTime"] is DBNull ? (new DateTime(1900, 1, 1)) : (DateTime)oDataRow["dtEndTime"];
            oInfo.iCompanyRemindID = oDataRow["iCompanyRemindID"] is DBNull ? 0 : (int)oDataRow["iCompanyRemindID"];
            oInfo.bIsEnable = oDataRow["bIsEnable"] is DBNull ? false : (bool)oDataRow["bIsEnable"];
            oInfo.iRemindCategoryID = oDataRow["iRemindCategoryID"] is DBNull ? 0 : (int)oDataRow["iRemindCategoryID"];

            if (oDataRow.Table.Columns.Contains("nvcEmployeeName"))
            {
                oInfo.nvcEmployeeName = oDataRow["nvcEmployeeName"] is DBNull ? "" : (string)oDataRow["nvcEmployeeName"];
            }

            return oInfo;
        }

        /// <summary>
        /// 分页获取所有的 CompanyRemindExtraInfo
        /// </summary>
        /// <param name="intPageNumber"></param>
        /// <param name="intPageSize"></param>
        /// <param name="strCondition"></param>
        /// <param name="strOrderby"></param>
        /// <param name="intRecordCount"></param>
        /// <returns></returns>
        public List<CompanyRemindExtraInfo> GetRemindExtraInfoListByPager(int intPageNumber, int intPageSize, string strCondition, string strOrderby, out int intRecordCount)
        {
            List<CompanyRemindExtraInfo> oList = new List<CompanyRemindExtraInfo>();
            try
            {
                DataSet oDataSet = CommonDAL.GetListByPager("vw_CompanyRemind", "*", intPageNumber, intPageSize, strCondition, strOrderby, out  intRecordCount, SystemInfoHelper.getSystemInfo().DataBaseConnection);
                DataTable oDataTable = oDataSet.Tables[0];
                foreach (DataRow otempRow in oDataTable.Rows)
                {
                    oList.Add(ParseRowRemindTomodel(otempRow));
                }
            }
            catch (Exception oeException)
            {
                throw new Exception(oeException.Message, oeException);
            }
            return oList;
        }

        /// <summary>
        /// 获取我的工作计划   计划 + Company 
        /// </summary>
        /// <param name="intPageNumber"></param>
        /// <param name="intPageSize"></param>
        /// <param name="strCondition"></param>
        /// <param name="strOrderby"></param>
        /// <param name="intRecordCount"></param>
        /// <returns></returns>
        public List<CompanyRemindExtraInfo> GetRemindCompanyListByPager(int intPageNumber, int intPageSize, string strCondition, string strOrderby, out int intRecordCount)
        {
            List<CompanyRemindExtraInfo> oList = new List<CompanyRemindExtraInfo>();
            try
            {
                DataSet oDataSet = CommonDAL.GetListByPager("vw_RemindCompany", "*", intPageNumber, intPageSize, strCondition, strOrderby, out  intRecordCount, SystemInfoHelper.getSystemInfo().DataBaseConnection);
                DataTable oDataTable = oDataSet.Tables[0];
                foreach (DataRow otempRow in oDataTable.Rows)
                {
                    oList.Add(ParseRowRemindTomodel(otempRow));
                }
            }
            catch (Exception oeException)
            {
                throw new Exception(oeException.Message, oeException);
            }
            return oList;
        }
        #endregion
    }
}
